﻿using System;
using System.Collections;
using System.Collections.Generic;
using Assets.Scripts.NetFrame;
using DG.Tweening;
using ExitGames.Client.Photon;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ApplicationClient : MonoBehaviour
{
    public static ApplicationClient _instance;
    public float ServicePeriod;

    void Awake()
    {
        if (_instance == null)
        {
            _instance = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            if(_instance != this)
                DestroyImmediate(gameObject);
        }
    }

    void Start ()
	{
        //todo 此处应该先检测是否有资源更新   XLUA热更新功能

        //开始连接游戏服务器
        print("开始连接服务器");
	    StartCoroutine(StartService(PhotonPeerManager.GetInstance().Init()));
        print("开始持续连接服务器");
	}

    IEnumerator StartService(PhotonPeer peer)
    {
        yield return new WaitForSecondsRealtime(ServicePeriod);
        peer.Service();
        StartCoroutine(StartService(peer));
    }

}
